package com.todo.strategy.offline.infrastructure.convert;

import com.alibaba.fastjson.JSONObject;
import com.google.api.client.util.Lists;
import com.todo.strategy.offline.infrastructure.entity.domain.MemoTemplateContentDO;
import com.todo.strategy.offline.infrastructure.entity.model.MemoTemplateContentModel;
import com.todo.strategy.offline.infrastructure.entity.po.MemoTemplatePO;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;

/**
 * @author azhebuxing
 * @date 2024/11/28 02:22
 * @description
 */
public class MemoConvert {

    public static MemoTemplatePO convertToMemoTemplatePO(MemoTemplateContentDO memoTemplateContentDO) {
        if (memoTemplateContentDO == null){
            return null;
        }
        MemoTemplatePO memoTemplatePO = new MemoTemplatePO();
        memoTemplatePO.setId(memoTemplateContentDO.getId());
        memoTemplatePO.setName(memoTemplateContentDO.getName());
        memoTemplatePO.setDesc(memoTemplateContentDO.getDesc());
        memoTemplatePO.setContent(JSONObject.toJSONString(memoTemplateContentDO.getContentModel()));
        memoTemplatePO.setBaseType(memoTemplateContentDO.getBaseType());
        memoTemplatePO.setReferenceOpinion(memoTemplateContentDO.getReferenceOpinion());
        memoTemplatePO.setSuggestStrategy(memoTemplateContentDO.getSuggestStrategy());
        memoTemplatePO.setUserId(memoTemplateContentDO.getUserId());
        memoTemplatePO.setCreateTime(memoTemplateContentDO.getCreateTime());
        memoTemplatePO.setUpdateTime(memoTemplateContentDO.getUpdateTime());
        memoTemplatePO.setIsPlatform(memoTemplateContentDO.getIsPlatform());
        memoTemplatePO.setUseCount(memoTemplateContentDO.getUseCount());
        memoTemplatePO.setStatus(memoTemplateContentDO.getStatus());
        memoTemplatePO.setIsDelete(memoTemplateContentDO.getIsDelete());
        return memoTemplatePO;
    }

    public static MemoTemplateContentDO convertToMemoTemplateContentDO(MemoTemplatePO memoTemplatePO) {
        if (memoTemplatePO == null){
            return null;
        }
        MemoTemplateContentDO memoTemplateContentDO = new MemoTemplateContentDO();
        memoTemplateContentDO.setId(memoTemplatePO.getId());
        memoTemplateContentDO.setName(memoTemplatePO.getName());
        memoTemplateContentDO.setDesc(memoTemplatePO.getDesc());
        memoTemplateContentDO.setContentModel(JSONObject.parseObject(memoTemplatePO.getContent(), MemoTemplateContentModel.class));
        memoTemplateContentDO.setBaseType(memoTemplatePO.getBaseType());
        memoTemplateContentDO.setReferenceOpinion(memoTemplatePO.getReferenceOpinion());
        memoTemplateContentDO.setSuggestStrategy(memoTemplatePO.getSuggestStrategy());
        memoTemplateContentDO.setUserId(memoTemplatePO.getUserId());
        memoTemplateContentDO.setCreateTime(memoTemplatePO.getCreateTime());
        memoTemplateContentDO.setUpdateTime(memoTemplatePO.getUpdateTime());
        memoTemplateContentDO.setIsPlatform(memoTemplatePO.getIsPlatform());
        memoTemplateContentDO.setUseCount(memoTemplatePO.getUseCount());
        memoTemplateContentDO.setStatus(memoTemplatePO.getStatus());
        memoTemplateContentDO.setIsDelete(memoTemplatePO.getIsDelete());
        return memoTemplateContentDO;
    }

    public static List<MemoTemplateContentDO> convertToMemoTemplatePOList(List<MemoTemplatePO> memoTemplatePOList) {
        if (CollectionUtils.isEmpty(memoTemplatePOList)){
            return Lists.newArrayList();
        }
        return memoTemplatePOList.stream().map(MemoConvert::convertToMemoTemplateContentDO).collect(java.util.stream.Collectors.toList());
    }
}
